<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUserWalletLogTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('user_wallet_log', ['comment' => '用户资金日志', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit'  =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('type', 'string', ['limit' => 10, 'comment' => '类型:money=余额,commission=佣金,score=积分'])
            ->addColumn('event', 'string', ['limit' => 255, 'comment' => '事件:money_recharge=充值,money_consume=余额消费,commission_withdraw=提现,commission_transfer=佣金转余额,commission_reward=佣金奖励,score_consume=积分消费,score_sign=积分签到,activity=活动赠送'])
            ->addColumn('amount', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '数量'])
            ->addColumn('before', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '变动前'])
            ->addColumn('after', 'decimal', ['precision' => 10, 'scale' => 2, 'default' => 0, 'comment' => '变动后'])
            ->addColumn('memo', 'string', ['limit' => 255, 'null' => true, 'default' => null, 'comment' => '备注'])
            ->addColumn('ext', 'string', ['limit' => 2500, 'null' => true, 'default' => null, 'comment' => '扩展信息'])
            ->addColumn('oper_type', 'string', ['limit' => 20, 'comment' => '操作人类型'])
            ->addColumn('oper_id', 'integer', ['limit' => 11, 'default' => 0, 'comment' => '操作人'])
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->create();
    }


    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('user_wallet_log');
        $table->drop();
    }
}
